package cn.imvc.app.controllers.info;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.controllers.goods.GoodsControllerImpl;
import cn.imvc.app.entities.Article;
import cn.imvc.app.models.ArticleClassModel;
import cn.imvc.app.models.ArticleModel;
import cn.imvc.app.models.LoggingModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;
/**
 * 
 * @author wjx
 *
 */
public class ArticleControllerImpl implements ArticleController {
	public Page<Article> page;
	public ViewRequest viewRequest;
	public Article article;
	public int id;
	public int classId;
	private OrgLookup orgLookup;
	public int[] ids;
	static Logger logger = Logger.getLogger(ArticleControllerImpl.class);
	@Autowired
	ArticleModel articleModel;
	@Autowired
	ArticleClassModel articleClassModel;
	@Autowired
	LoggingModel loggingModel;
	public String search() {
		return null;
	}

	public String index() {
		if(viewRequest==null){
			viewRequest = new ViewRequest();
		}
		page=articleModel.find(viewRequest);
		return "article/index";
	}

	public String show() { 
		return null;
	}

	public String editNew() {
		return "article/edit";
	}

	public String create() {
		articleModel.save(article,orgLookup.getId());
		return Render.json(new DialogBean("200", "创建成功","", "closeCurrent"));
	}

	public String edit() {
		article=articleModel.get(id);
		return "article/edit";
	}

	public String update() {
		articleModel.update(id,article,orgLookup.getId());
		return Render.json(new DialogBean("200", "修改成功","", "closeCurrent"));
	}

	public String destroy() {
		
		articleModel.delete(id);
		return Render.json(new DialogBean("200", "删除成功",""));
	
	}

	public String destroyBatch() {
		articleModel.deleteBatch(ids);
		return Render.json(new DialogBean("200", "删除成功",""));
	}
	/**
	 * 外部调用
	 */
	public String dialog() {
		if(viewRequest==null){
			viewRequest = new ViewRequest();
		}
		page=articleModel.find(viewRequest);
		return "article/dialog";
	}
	
	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}

	public Article getArticle() {
		return article;
	}

	public void setArticle(Article article) {
		this.article = article;
	}
	
	public void setId(int id) {
		this.id = id;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}
	
	public void setClassId(int classId) {
		this.classId = classId;
	}
	
	public OrgLookup getOrgLookup() {
		return orgLookup;
	}

	public void setOrgLookup(OrgLookup orgLookup) {
		this.orgLookup = orgLookup;
	}


	
	
}
